<template>
	<el-main class="bg edit_wrap comtable_e">
		<el-form ref="form" :model="form" status-icon label-width="120px" v-if="is_view()">
		<el-row class="row_ce"> 
							<el-col v-if="user_group === '管理员' || $check_field('get','announcement_number') || $check_field('add','announcement_number') || $check_field('set','announcement_number')" :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
				<el-form-item label="公告编号" prop="announcement_number">
												<el-input id="announcement_number" v-model="form['announcement_number']" placeholder="请输入公告编号"
							  v-if="user_group === '管理员' || (form['notification_announcement_id'] && $check_field('set','announcement_number')) || (!form['notification_announcement_id'] && $check_field('add','announcement_number'))" :disabled="true"></el-input>
					<div v-else-if="$check_field('get','announcement_number')">{{form['announcement_number']}}</div>
											</el-form-item>
			</el-col>
								<el-col v-if="user_group === '管理员' || $check_field('get','announcement_title') || $check_field('add','announcement_title') || $check_field('set','announcement_title')" :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
				<el-form-item label="公告标题" prop="announcement_title">
												<el-input id="announcement_title" v-model="form['announcement_title']" placeholder="请输入公告标题"
							  v-if="user_group === '管理员' || (form['notification_announcement_id'] && $check_field('set','announcement_title')) || (!form['notification_announcement_id'] && $check_field('add','announcement_title'))" :disabled="disabledObj['announcement_title_isDisabled']"></el-input>
					<div v-else-if="$check_field('get','announcement_title')">{{form['announcement_title']}}</div>
											</el-form-item>
			</el-col>
								<el-col v-if="user_group === '管理员' || $check_field('get','announcement_date') || $check_field('add','announcement_date') || $check_field('set','announcement_date')" :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
				<el-form-item label="公告日期" prop="announcement_date">
								<el-date-picker :disabled="disabledObj['announcement_date_isDisabled']" v-if="user_group === '管理员' || (form['notification_announcement_id'] && $check_field('set','announcement_date')) || (!form['notification_announcement_id'] && $check_field('add','announcement_date'))" id="announcement_date"
						v-model="form['announcement_date']" type="date" placeholder="选择日期">
					</el-date-picker>
					<div v-else-if="$check_field('get','announcement_date')">{{form['announcement_date']}}</div>
							</el-form-item>
			</el-col>
								<el-col v-if="user_group === '管理员' || $check_field('get','announcement_image') || $check_field('add','announcement_image') || $check_field('set','announcement_image')" :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
				<el-form-item label="公告图片" prop="announcement_image">
								<el-upload :disabled="disabledObj['announcement_image_isDisabled']" id="announcement_image" class="avatar-uploader" drag
						accept="image/gif, image/jpeg, image/png, image/jpg" action="" :http-request="upload_announcement_image"
						:show-file-list="false" v-if="user_group === '管理员' || (form['notification_announcement_id'] && $check_field('set','announcement_image')) || (!form['notification_announcement_id'] && $check_field('add','announcement_image'))">
						<img v-if="form['announcement_image']" :src="$fullUrl(form['announcement_image'])" class="avatar">
						<i v-else class="el-icon-plus avatar-uploader-icon"></i>
					</el-upload>
					<el-image v-else-if="$check_field('get','announcement_image')" style="width: 100px; height: 100px"
						:src="$fullUrl(form['announcement_image'])" :preview-src-list="[$fullUrl(form['announcement_image'])]">
						<div slot="error" class="image-slot">
							<img src="../../../public/img/error.png" style="width: 90px; height: 90px" />
						</div>
					</el-image>
							</el-form-item>
			</el-col>
								<el-col v-if="user_group === '管理员' || $check_field('get','announcement_content') || $check_field('add','announcement_content') || $check_field('set','announcement_content')" :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
				<el-form-item label="公告内容" prop="announcement_content">
								<el-input type="textarea" id="announcement_content" v-model="form['announcement_content']" placeholder="请输入公告内容"
						v-if="user_group === '管理员' || (form['notification_announcement_id'] && $check_field('set','announcement_content')) || (!form['notification_announcement_id'] && $check_field('add','announcement_content'))" :disabled="disabledObj['announcement_content_isDisabled']"></el-input>
					<div v-else-if="$check_field('get','announcement_content')">{{form['announcement_content']}}</div>
							</el-form-item>
			</el-col>
					
	
	
	
	
	
	
		</el-row>
			<el-col :xs="24" :sm="12" :lg="8" class="el_form_btn_warp">
				<el-form-item v-if="$check_action('/notification_announcement/view','set') || $check_action('/notification_announcement/view','add') || $check_option('/notification_announcement/table','examine')">
					<el-button type="primary" @click="submit()">提交</el-button>
					<el-button @click="cancel()">取消</el-button>
				</el-form-item>
				<el-form-item v-else>
					<el-button @click="cancel()">返回</el-button>
				</el-form-item>
			</el-col>

		</el-form>
	</el-main>
</template>

<script>
	import mixin from "@/mixins/page.js";

	export default {
		mixins: [mixin],
		data() {
			return {
				field: "notification_announcement_id",
				url_add: "~/api/notification_announcement/add?",
				url_set: "~/api/notification_announcement/set?",
				url_get_obj: "~/api/notification_announcement/get_obj?",
				url_upload: "~/api/notification_announcement/upload?",

				query: {
					"notification_announcement_id": 0,
				},

				form: {
								"announcement_number": this.$get_stamp(), // 公告编号
										"announcement_title":  '', // 公告标题
										"announcement_date":  '', // 公告日期
										"announcement_image":  '', // 公告图片
										"announcement_content":  '', // 公告内容
											"notification_announcement_id": 0, // ID
						
				},
				disabledObj:{
								"announcement_number_isDisabled": false,
										"announcement_title_isDisabled": false,
										"announcement_date_isDisabled": false,
										"announcement_image_isDisabled": false,
										"announcement_content_isDisabled": false,
										},

	
		
		
		
		
	
			}
		},
		methods: {


	
	
			
	
			
	
						/**
			 * 上传公告图片
			 * @param {Object} param 图片参数
			 */
			upload_announcement_image(param){
						this.uploadFile(param.file, "announcement_image");
					},
	
	
			
	
		
			/**
			 * 获取对象之前
			 * @param {Object} param
			 */
			get_obj_before(param) {
				var form = "";
																															
				if(this.form && form){
					Object.keys(this.form).forEach(key => {
						Object.keys(form).forEach(dbKey => {
							// if(dbKey === "charging_standard"){
							// 	this.form['charging_rules'] = form[dbKey];
							// 	this.disabledObj['charging_rules_isDisabled'] = true;
							// };
							if(key === dbKey){
								this.disabledObj[key+'_isDisabled'] = true;
							}
						})
					})
				}
						        if (this.form["announcement_date"] && this.form["announcement_date"].indexOf("-")===-1){
          this.form["announcement_date"] = this.$toTime(parseInt(this.form["announcement_date"]),"yyyy-MM-dd")
        }
									$.db.del("form");

				return param;
			},

			/**
			 * 获取对象之后
			 * @param {Object} json
			 * @param {Object} func
			 */
			get_obj_after(json, func){
														if(this.form["announcement_date"]=="0000-00-00"){
				  this.form["announcement_date"] = null;
				}
				if(parseInt(this.form["announcement_date"]) > 9999){
					this.form["announcement_date"] = this.$toTime(parseInt(this.form["announcement_date"]),"yyyy-MM-dd")
				}
											

			},

			/**
			 * 提交前验证事件
			 * @param {Object} 请求参数
			 * @return {String} 验证成功返回null, 失败返回错误提示
			 */
			submit_check(param) {
																										if (!param.announcement_date){
					return "公告日期不能为空";
				}
																															return null;
			},

			is_view(){
				var bl = this.user_group == "管理员";

				if(!bl){
					bl = this.$check_action('/notification_announcement/table','add');
					console.log(bl ? "你有表格添加权限视作有添加权限" : "你没有表格添加权限");
				}
				if(!bl){
					bl = this.$check_action('/notification_announcement/table','set');
					console.log(bl ? "你有表格添加权限视作有修改权限" : "你没有表格修改权限");
				}
				if(!bl){
					bl = this.$check_action('/notification_announcement/view','add');
					console.log(bl ? "你有视图添加权限视作有添加权限" : "你没有视图添加权限");
				}
				if(!bl){
					bl = this.$check_action('/notification_announcement/view','set');
					console.log(bl ? "你有视图修改权限视作有修改权限" : "你没有视图修改权限");
				}
				if(!bl){
					bl = this.$check_action('/notification_announcement/view','get');
					console.log(bl ? "你有视图查询权限视作有查询权限" : "你没有视图查询权限");
				}

				console.log(bl ? "具有当前页面的查看权，请注意这不代表你有字段的查看权" : "无权查看当前页，请注意即便有字段查询权限没有页面查询权限也不行");

				return bl;
			},
			/**
			 * 上传文件
			 * @param {Object} param
			 */
			uploadimg(param) {
				this.uploadFile(param.file, "avatar");
			},

		},
		created() {
												},
	}
</script>

<style>
	.avatar-uploader .el-upload {
		border: 1px dashed #d9d9d9;
		border-radius: 6px;
		cursor: pointer;
		position: relative;
		overflow: hidden;
	}

	.avatar-uploader .el-upload:hover {
		border-color: #409EFF;
	}

	.avatar-uploader-icon {
		font-size: 28px;
		color: #8c939d;
		width: 178px;
		height: 178px;
		line-height: 178px;
		text-align: center;
	}

	.avatar {
		width: 178px;
		height: 178px;
		display: block;
	}




</style>
